package tk.xly;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import tk.model.Users;

public class JunitHibernate {
	private SessionFactory sessionFactory;
	private Session session;
	
	@Before
	public void init()
	{
/*		ApplicationContext app=new ClassPathXmlApplicationContext("Spring.xml");
		sessionFactory=app.getBean(SessionFactory.class);
		session=sessionFactory.openSession();*/
//		Configuration config=new Configuration().configure("hibernate-cfg.xml");
//		ServiceRegistry service=new ServiceRegistryBuilder()
//				.applySettings(config.getProperties())
//				.buildServiceRegistry();
//		sessionFactory=config.buildSessionFactory(service);
//		session=sessionFactory.openSession();
		//session.beginTransaction();
	}
	@After
	public void destory()
	{
		//session.getTransaction().commit();
		//session.close();
		//sessionFactory.close();
	}
	@Test
	public void test()
	{
//		Users user=(Users)session.get(Users.class, 1);
		Users user=new Users().showUser();
		System.out.println(user.getId()+" "+user.getUsername()+" "+user.getPassword());
		
//		Users user=new Users();
//		user.setId(1);
//		user.setUsername("XLY");
//		user.setPassword("123456");
//		session.save(user);
	}
}
